/**
 *
 */
package org.whuims.pois.action;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.whuims.pois.action.result.ClusterVo;
import org.whuims.pois.dao.ClusterDao;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


/**
 * @author herochen
 * @date 2010-4-17  @time 下午08:47:35
 */
public class ClusterAction extends DispatchAction {

    private List<ClusterVo> list = new ArrayList<ClusterVo>();
    private ClusterDao dao = new ClusterDao();

    public ActionForward yesterday(ActionMapping mapping, ActionForm form,
                                   HttpServletRequest request, HttpServletResponse response) {
        long topicId = getTopic(request);

        if (topicId <= 0) {
            return mapping.findForward("login");
        }
        list = dao.getYesterdayList(topicId);
        request.setAttribute("result", list);
        request.setAttribute("tag", "昨日聚焦");
        return mapping.findForward("success");
    }

    public ActionForward today(ActionMapping mapping, ActionForm form,
                               HttpServletRequest request, HttpServletResponse response) {
        long topicId = getTopic(request);
        if (topicId <= 0) {
            return mapping.findForward("login");
        }
        list = dao.getTodayList(topicId);
        request.setAttribute("result", list);
        request.setAttribute("tag", "今日要点");
        return mapping.findForward("success");
    }

    public ActionForward week(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request, HttpServletResponse response) {
        long topicId = getTopic(request);
        if (topicId <= 0) {
            return mapping.findForward("login");
        }
        list = dao.getWeekList(topicId);
        request.setAttribute("result", list);
        request.setAttribute("tag", "本周热议");
        return mapping.findForward("success");
    }

    private long getTopic(HttpServletRequest request) {
        Object topic = request.getSession().getAttribute("topicId");
        if (topic == null) {
            return -1;
        }
        return (Long) topic;
    }


}
